CREATE TABLE [dbo].[StarProfileLike](
	[StarProfileSceneId] [int] NOT NULL,
	[IP] [varchar](50) NOT NULL,
	[IsLiked] [bit] NOT NULL,
 CONSTRAINT [PK_StarProfileLike] PRIMARY KEY CLUSTERED 
(
	[StarProfileSceneId] ASC,
	[IP] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[StarProfileLike]  WITH CHECK ADD  CONSTRAINT [FK_StarProfileLike_StarProfileScene] FOREIGN KEY([StarProfileSceneId])
REFERENCES [dbo].[StarProfileScene] ([StarProfileSceneId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[StarProfileLike] CHECK CONSTRAINT [FK_StarProfileLike_StarProfileScene]
GO
create PROCEDURE spStarProfile_Like
(
	@StarProfileSceneId INT,
	@IP varchar(50),
	@IsLiked bit
)
AS
BEGIN
	SET NOCOUNT ON
	
	if not exists(select 1 from StarProfileLike (nolock) where (StarProfileSceneId = @StarProfileSceneId) and (IP = @IP))
		insert into StarProfileLike
		(StarProfileSceneId, IP, IsLiked)
		values (@StarProfileSceneId, @IP, @IsLiked)
	else
		update StarProfileLike
		set IsLiked = @IsLiked
		where (StarProfileSceneId = @StarProfileSceneId) 
			and (IP = @IP)
END
go